﻿@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiList.cshtml"; }

<!--数据表格-->
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>

<script>
    layui.use(["table", "form", "exLayer", "exUtils", "miniPage"], function () {
        let table = layui.table;
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let miniPage = layui.miniPage;

        let $ = layui.$;
        var openWH = miniPage.getOpenWidthHeight();

        let ThisTable = table.render({
            elem: "#tableId",
            url: "/SysBasic/Organize/GetList",
            defaultToolbar: ['exports'],
            toolbar: "#toolbarTpl",
            cols: [[
                { field: "Value", title: "编码", width: 150 },
                { field: "Text", title: "名称" },
                { title: "操作", width: 120, align: "center", fixed: "right", templet: "#operationTpl" }
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "add":
                    add();
                    break;
            }
        });

        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "edit":
                    edit(data.Value);
                    break;
                case "del":
                    del(data.Value);
                    break;
            }
        });

        function add() {
            exLayer.openMiddle("新建单位(部门)", "/SysBasic/Organize/Add", '500px', '450px', null, null);
        }

        function edit(id) {
            exLayer.openMiddle("编辑单位(部门)", "/SysBasic/Organize/Edit/" + id, '500px', '450px', null, null);
        }

        function del(id) {
            exLayer.confirm("确定要删除吗？", function () {
                exUtils.ajax("/SysBasic/Organize/Delete", "get", { id: id }, true).done(function (response) {
                    ThisTable.reload({
                    });
                    exUtils.tableSuccessMsg(response.message);
                }).fail(function (error) {
                    console.log(error);
                });
            })
        }
    });
</script>
<!-- 头工具栏模板-->
<script type="text/html" id="toolbarTpl">
    <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="add" id="add"><i class="fa fa-plus"></i>新建单位（部门）</button>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" id="edit">编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" id="del">删除</a>
</script>